<template>
  <div>
    <Modal
        :title="modelObiect.title"
        v-model="modal"
        :mask-closable="false"
        :closable="false"
        :okText="modelObiect.okText"
        :cancelText="modelObiect.cancelText"
        >
        <slot name="mainContent" />

        <div slot="footer">
          <Button @click="modal = false">{{ modelObiect.cancelText }}</Button>
          <Button type="primary" @click="handleOKEvent">{{ modelObiect.okText }}</Button>
        </div>
    </Modal>
  </div>
</template>

<script>
export default {
  props: {
    modelObiect: {
      type: Object,
      default: () =>{}
    },
    modalShow: {
      type: Boolean,
      default: false
    },
    dataTransmission: {
      type: Object,
      default: () =>{}
    }
  },
  data () {
    return {
      modal: this.modalShow,
      receiveData: this.dataTransmission
    };
  },
  watch:{
    modal(val) {
      // 当前界面弹框的显示操作的监听并向父级传递
      this.$emit('on-isshow-change', val);
    }
  },
  methods:{
    handleOKEvent() {
      switch (this.modelObiect.sureEventType){
      case 'info':
        this.$emit('child-operation', this.receiveData);
        break;

      case 'updateKey':
        if (this.receiveData.verification) {
          this.modal = false;
          this.$emit('child-operation', this.receiveData);
        } else {
          this.$Message.error('数据验证不通过！请检查！');
        }

        break;
      default:
        break;
      }
    }
  }
};
</script>

<style>
</style>
